// Deal.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Collections.Generic;

using Supremacy.Entities;
using Supremacy.Game;

namespace Supremacy.Diplomacy
{
    [Serializable]
    public sealed class Deal
    {
        private int _senderId;
        private int _recipientId;
        private readonly List<TradeData> _senderItems;
        private readonly List<TradeData> _recipientItems;

        public Deal()
        {
            _senderItems = new List<TradeData>();
            _recipientItems = new List<TradeData>();
        }

        public Deal(Civilization sender) : this()
        {
            if (sender == null)
                throw new ArgumentNullException("sender");
            Sender = sender;
        }

        public Deal(Civilization sender, Civilization recipient) : this()
        {
            if (sender == null)
                throw new ArgumentNullException("sender");
            if (recipient == null)
                throw new ArgumentNullException("recipient");
            Sender = sender;
            Recipient = recipient;
        }

        public Civilization Sender
        {
            get
            {
                if (_senderId == Civilization.InvalidID)
                    return null;
                return GameContext.Current.Civilizations[_senderId];
            }
            set
            {
                _senderId = (value == null)
                    ? Civilization.InvalidID
                    : value.CivID;
            }
        }

        public Civilization Recipient
        {
            get
            {
                if (_recipientId == Civilization.InvalidID)
                    return null;
                return GameContext.Current.Civilizations[_recipientId];
            }
            set
            {
                _recipientId = (value == null)
                    ? Civilization.InvalidID
                    : value.CivID;
            }
        }

        public IList<TradeData> SenderItems
        {
            get { return _senderItems; }
        }

        public IList<TradeData> RecipientItems
        {
            get { return _recipientItems; }
        }

        // TODO Incorporate CvDeal doTurn() logic...

        //internal void OnTurn()
        //{
        //    if (IsPeaceDeal)
        //    {
                
        //    }
        //}

        //private bool IsPeaceDeal
        //{
        //    get { throw new EXCEPTION(); }
        //}
    }
}
